<?php
//session_start();
require_once  '../classes/ConnectionDB.php';
require_once  '../classes/UtenteManager.php';

$username = $_POST["username"];
$password =$_POST['password'];
$scuola = $_POST['scuola'];
$tipoUtente = $_POST['tipoUtente'];

//
//echo 'username= '.$username;
//echo 'password = '.$password;
$db =ConnectionDB::getInstance()->connectToDB();

if($tipoUtente=='docente')
    $codiceUtente = UtenteManager::getInstance()->checkLogin($db, $username, $password, $scuola);
else
    $codiceUtente = UtenteDataManager::getInstance()->checkLoginStudente($db, $username, $password, $scuola);

if($codiceUtente != -1)
{
    setcookie('username', $username, time()-3600, "/");
    setcookie('codiceUtente', $codiceUtente, time()-3600, "/");
    setcookie('codiceScuola', $scuola, time()-3600, "/");
    setcookie('username', $username, time()+3600, "/");
    setcookie('codiceUtente', $codiceUtente, time()+3600, "/");
    setcookie('codiceScuola', $scuola, time()+3600, "/");
//    header("Location: menu.php");
if($tipoUtente=='docente')
    header("Location: newMenu.php");
else
    header("Location: ../studente/index.php");
}
else
   header("Location: errors/error.php");





?>
